/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kedacom.demo.jmx;

import com.kedacom.demo.sigar.util.SigarUtil;
import java.lang.management.ManagementFactory;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanServer;
import javax.management.ObjectName;

/**
 *
 * @author Administrator
 */
public class JMXUtil {

    private static final Logger logger = Logger.getLogger(SigarUtil.class.getName());
    private static MBeanServer server;

    static {
        MBeanServer server;
        server = ManagementFactory.getPlatformMBeanServer();//for jdk5.0+
    }

    public static void registerMBean() {
        //todo
    }

    public static Set<ObjectName> getAllNames() {
        Set<ObjectName> beans = null;
        try {
            beans = server.queryNames(new ObjectName("sigar:*"), null);
            for (ObjectName name : beans) {
                MBeanInfo info = server.getMBeanInfo(name);
                MBeanAttributeInfo[] attrs = info.getAttributes();
                for (int k = 0; k < attrs.length; k++) {
                    String attr = attrs[k].getName();
                    Object o = server.getAttribute(name, attr);
                }
            }
        }
        catch (Exception ex) {
            logger.log(Level.SEVERE, null, ex);
        }
        return beans;
    }
}
